import Packet from "../net/Packet"

// 服务器断开连接
export default class SystemDisconnect {
	/**
	 * @param code 错误代码
	 */
	public constructor(public code: number) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(1020)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): SystemDisconnect {
		const code = packet.ReadUshort()
		return new SystemDisconnect(code)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUshort(this.code)
		return packet
	}
}
